const { Sequelize , DataTypes} = require('sequelize')
const {database,username,password,host} = require('../config')
const sequelize = new Sequelize(database, username,password, {
    host,
    dialect: 'mysql',
  });

const connectDb =async function(){
    try {
        await sequelize.authenticate();
        console.log('Connection has been established successfully.');
      } catch (error) {
        console.error('Unable to connect to the database:', error);
      }
}
const User= sequelize.define('user',{
    id:{
        type:DataTypes.INTEGER,
        primaryKey:true,
        autoIncrement:true,
    },
})
const init = async ()=>{
    await sequelize.sync({force:true})
}
connectDb()
const DB ={
    User,
    init
}
module.exports ={
    sequelize,
    DB,
}